<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class admin_model extends CI_model {
    
    function __construct() {
        parent::__construct();
        $this->load->database();
    }
    
    public function cek_login($email, $pass){
        $pass_ = md5($pass);
        $query = $this->db->get_where('ADMIN', array('ADMIN_EMAIL'=> $email,'ADMIN_PASSWORD'=> $pass_),1);
        if ($query->num_rows() > 0)  return $query->row();
        else return FALSE;
    }
    
    public function insert_path_foto($path,$last_id){
        $data = array(
            'ADMIN_FOTO' => $path
        );
        $this->db->where('ADMIN_ID',$last_id);
        $this->db->update('admin', $data);
    }
    
    public function insert_admin($username,$email,$nohp,$alamat,$pass,$status,$path_foto){

        $data = array(
            'ADMIN_USERNAME' => $username,
            'ADMIN_EMAIL' => $email,
            'ADMIN_NO_HP' => $nohp,
            'ADMIN_ALAMAT' => $alamat,
            'ADMIN_PASSWORD' => md5($pass),
            'ADMIN_STATUS' => $status,
        );
        $this->db->insert('admin', $data);    
    }
    
    public function update_admin($admin_id, $username,$email,$nohp,$alamat,$status){

        $data = array(
            'ADMIN_USERNAME' => $nama,
            'ADMIN_EMAIL' => $email,
            'ADMIN_NOHP' => $nohp,
            'ADMIN_ALAMAT' => $alamat,
            'ADMIN_STATUS' => $status,
        );

        $this->db->where('ADMIN_ID',$admin_id);
        $result = $this->db->update('admin', $data);
        return $result; 
    }
    
    public function change_pwd($admin_id,$admin_email, $passold, $passnew)
    {
        $data = array(
            'ADMIN_PASSWORD' => md5($passnew), 
        );
        $this->db->where('ADMIN_ID',$admin_id);
        $this->db->where('ADMIN_EMAIL',$admin_email);
        $this->db->where('ADMIN_PASSWORD', md5($passold));
        $result = $this->db->update('ADMIN', $data);
    }
    
    public function get_admin($admin_id)
    {
        $this->db->where('ADMIN_ID',$admin_id);
        $query = $this->db->get('admin');
        return $query;
    }
    
    public function del_admin($admin_id){
        $this->db->where('ADMIN_ID', $admin_id);
        $this->db->delete('admin');
    }
}